#include <QString>
#include <json\json.h>
#include "Card_CVR100UDDLL.h"
#include <QTextCodec>
#include <QApplication>

char buffer[4096];
int console_main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	QTextCodec::setCodecForTr(QTextCodec::codecForLocale());	
	QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());	

	AbstractLock *lock = NULL;
	Json::Value json_param;
	json_param["cardType"] = 1;

	Card_CVR100UDDLL *dll = new Card_CVR100UDDLL();
	dll->DealCommand("ReadIDCard",json_param);
	return 0;

	bool m_run = true;
	while(m_run)
	{
		fgets(buffer,4096,stdin);
		
		Json::FastWriter w;
		Json::Reader r;
		Json::Value json_cmd;
		Json::Value json_ret;

		QByteArray recv = buffer;
		recv = QByteArray::fromBase64(recv);

		if(r.parse(recv.data(),json_cmd))
		{
			QString cmd = json_cmd["InternalCommand"].asCString();
			if(cmd == "init")
			{
				QString dll = json_cmd["dll"].asCString();
				if(dll == "CVR100UDDLL")
				{
					Card_CVR100UDDLL *dll = new Card_CVR100UDDLL();
					if(dll->isVaild())
						lock = dll;
					else
						delete dll;
				}
				
				if(lock)
				{
					json_ret.clear();
					json_ret["code"] = 0;			
				}
				else
				{
					json_ret.clear();
					json_ret["code"] = -1;
					json_ret["message"] = "Dll init failed";	
					m_run = false;
				}
			}
			else if(cmd == "exit")
			{
				json_ret["code"] = 0;
				m_run = false;
			}
			else
			{
				json_ret = lock->DealCommand(cmd,json_cmd);
			}
		}
		else
		{
			json_ret.clear();
			json_ret["code"] = -1;
			json_ret["message"] = "Dll input invalid";			
		}			

		//send		
		string str_ret = w.write(json_ret);	
		QByteArray data(str_ret.data(),str_ret.size());
		data = data.toBase64();
		printf("%s\n",data.data());		
	}

	if(lock)
		delete lock;

	return 0;
}